function checkSub(val){
	
	if(document.getElementById('voucher_type').value==''){
		alert('优惠券类型不能为空');
		document.getElementById('voucher_type').focus();
		return false;
	}
	
	if(document.getElementById('voucher_name').value==''){
		alert('优惠券名称不能为空');
		document.getElementById('voucher_name').focus();
		return false;
	}
	if(document.getElementById('usage_rules').value==''){
		alert('使用规则不能为空');
		document.getElementById('usage_rules').focus();
		return false;
	}
	var start=document.getElementById('start_time').value;
	var end=document.getElementById('end_time').value;
	if(start==''){
		alert('开始时间不能为空');
		document.getElementById('start_time').focus();
		return false;
	}	
	
	if(end==''){
		alert('结束时间不能为空');
		document.getElementById('end_time').focus();
		return false;
	}
	if(!checkTime(start,end)){
		document.getElementById('start_time').focus();
		return false;
	}
	var beginDate =  new Date(document.getElementById('start_time').value.replace(/-/g,"/"));
    var endDate = new Date(document.getElementById('end_time').value.replace(/-/g,"/"));     
    
	if(beginDate>endDate)
	{
	   alert("开始的时间必须小于结束时间");
	   document.getElementById('end_time').focus();
	   return false;
    }
		
	
	
	if(val=='addForm'){
		if(document.getElementById('number').value==''){
			alert('数量不能为空');
			document.getElementById('number').focus();
			return false;
		}
	}
	
	if(document.getElementById('money').value==''){
		alert('金额不能为空');
		document.getElementById('money').focus();
		return false;
	}
	
	if(document.getElementById('property_type').value==''){
		alert('财产类型不能为空');
		document.getElementById('property_type').focus();
		return false;
	}
	if(val=='addForm')
		document.addForm.submit();
	else
		document.updateForm.submit();
}

function checkRule(val){
	var type=document.getElementById('voucher_type').value;
	var level=document.getElementById('member_level').value;
	if(type==''){
		alert('优惠券类型不能为空');
		document.getElementById('voucher_type').focus();
		return false;
	}
	if(level==''){
		alert('会员级别不能为空');
		document.getElementById('member_level').focus();
		return false;
	}
	if(document.getElementById('limit_number').value==''){
		alert('限制数量不能为空');
		document.getElementById('limit_number').focus();
		return false;
	}
	if(val=='addRuleForm'){
		Ti_PaymentRulesInfo.getRulebyType(type,level,function(data){
			if(data>0){
				alert("已经有相同的优惠券类型存在");
				document.getElementById('voucher_type').focus();
			}else{
				document.addRuleForm.submit();
			}
	});
	}
	if(val!='addRuleForm')
		document.updateRuleForm.submit();	
}

function setType(val){
	var type="";
	 for(i=0;i<val.length;i++){   
                if(val.options[i].selected){
                    type=val.options[i].text;
                }
            }
            document.getElementById("voucher_type").value=type;
}

function search(val){
	if(val=='paymentrulesForm')
		document.paymentrulesForm.submit();
	else
		document.indexForm.submit();
}



